###########################################################################
#	$Id: _test.html 24 2007-05-01 07:52:43Z beave $
###########################################################################

@main[][sTestFile;sLogsDir;bDebug;sFullPath;sCurrentDir;oDebug;hArchives;tDirFiles]

^use[Archive.p]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xml:lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=$response:charset" />
		<title>Parser 3. Archive. Test file.</title>
	</head>

	<body>
		<h1>Archive. Test file.</h1>


		^rem{ *** declaring variables *** }
		
		$ARCHIVE_NAME[test]
		
		$sTestFile[_test.html]
		$sLogsDir[/../data/logs]
		$bDebug(true)
		
		$sFullPath[^file:fullpath[$sTestFile]]
		$sCurrentDir[^sFullPath.left(^sFullPath.pos[$sTestFile])]
		
		
#		if turned on debug-mode loading class and creating object
		^if($bDebug){
			^use[Debug.p]
		
			$oDebug[^Debug::create[
				$.LOG_PATH[${sLogsDir}/archive.xml]
				$.GUESS_TYPE(true)
				$.APPEND(false)
			]]
		}
		
		
#		initializing Archive class
		^Archive:init[
			^if($bDebug){
				$.DEBUG_OBJECT[$oDebug]
			}
		]


		$hArchives[
			$.1[
				$.file[$sCurrentDir/${ARCHIVE_NAME}.tar.gz]
				$.content[^table::create{path
..$sCurrentDir/readme_ru.html
$sCurrentDir/readme_en.html}]
			]
			$.2[
				$.file[${ARCHIVE_NAME}.tar.bz2]
				$.content[^table::create{path
..$sCurrentDir/readme_en.html
$sCurrentDir/readme_en.html
readme_en.html}]
			]
			$.3[
				$.file[..$sCurrentDir/${ARCHIVE_NAME}.zip]
				$.content[/archive/readme_ru.html]
			]
			$.4[
				$.file[$sCurrentDir/${ARCHIVE_NAME}.rar]
				$.content[${sWebPath}/archive/readme_en.html]
			]
		]
		
		^rem{ *** END declating variables *** }


		<h2>Create archives.</h2>
		
		^for[i](1;^hArchives._count[]){
			^try{
				^Archive:create[$hArchives.[$i].file;$hArchives.[$i].content]
			}{
				^if($exception.type eq 'Archive.search'){
					$exception.handled(true)
					^printError[Could not find a file ($exception.source).]
				}
			}
		}
		
		$tDirFiles[^getDirFiles[$sCurrentDir]]
		^if($tDirFiles){
			<p>Archives in ${sCurrentDir}:</p>
			<pre>
			^tDirFiles.menu{
				$tDirFiles.name
			}
			</pre>
		}


		<h2>View archives.</h2>
		^for[i](1;^hArchives._count[]){
			^try{
				^printArchiveContent[$hArchives.[$i].file]
			}{
				^if($exception.type eq 'Archive.file.missing'){
					$exception.handled(true)
					^printError[Could not find a file ($exception.source).]
				}
			}
		}
		
		
		<h2>Extract archives.</h2>
		^for[i](1;^hArchives._count[]){
			^try{
				^Archive:extract[$hArchives.[$i].file;${ARCHIVE_NAME}_$i]
			}{
				^if($exception.type eq 'Archive.file.missing'){
					$exception.handled(true)
					^printError[Could not find a file ($exception.source).]
				}
			}
			<pre>
				^printDirectoryContent[test_${i}]
			</pre>
		}
	</body>
</html>
#end @main[]



###########################################################################
#	Result: string
###########################################################################
@printError[strComment]
<p style="color: red">$strComment</p>
#end @printError[]



###########################################################################
#	Result: table
###########################################################################
@getDirFiles[sDir]
^file:list[$sDir;^^${ARCHIVE_NAME}\.]
#end @getDirFiles[]



###########################################################################
#	Result: string
###########################################################################
@printArchiveContent[sFile][tContent]
<p>Content of ${sFile}:</p>

$tContent[^Archive:list[$sFile]]

^if($tContent){
	<table border="1">
		<thead>
			<tr>
				<th>Path</th>
				<th>Size</th>
				<th>Date &amp^; Time</th>
				^switch[$Archive:ARCHIVER]{
					^case[tar]{
						<th>Rights</th>
						<th>User</th>
						<th>Group</th>
						<th>Link</th>
					}
					^case[zip]{
						<th>EAs</th>
						<th>ACLs</th>
					}
					^case[rar]{
						<th>Rights</th>
						<th>Packed</th>
						<th>Ratio</th>
						<th>CRC</th>
						<th>Method</th>
						<th>Version</th>
					}
				}
			</tr>
		</thead>
		<tbody>
			^tContent.menu{
				<tr>
					<td>$tContent.path</td>
					<td>$tContent.size</td>
					<td>$tContent.dt</td>
					^switch[$Archive:ARCHIVER]{
						^case[tar]{
							<td>$tContent.rights</td>
							<td>$tContent.user</td>
							<td>$tContent.group</td>
							^if(def $tContent.link){
								<td>$tContent.link</td>
							}
						}
						^case[zip]{
							^if(def $tContent.ea){
								<td>$tContent.ea</td>
							}
							^if(def $tContent.acl){
								<td>$tContent.acl</td>
							}
						}
						^case[rar]{
							<td>$tContent.rights</td>
							<td>$tContent.packed</td>
							<td>$tContent.ratio</td>
							<td>$tContent.crc</td>
							<td>$tContent.method</td>
							<td>$tContent.version</td>
						}
					}
				</tr>
			}
		</tbody>
	</table>
}
#end @printArchiveContent[]



###########################################################################
#	Result: string
###########################################################################
@printDirectoryContent[strPath][tContent;sPath]
$tContent[^file:list[$strPath]]

^if($tContent){
	^tContent.menu{
		$sPath[${strPath}/$tContent.name]
		^if(-d $sPath){
			^printDirectoryContent[$sPath]
		}{
			$sPath
		}

	}
}
#end @printDirectoryContent[]
